/*
 * @(#)ServiceExecutionContext.java $version 2010. 8. 11
 *
 * Copyright 2007-2010 NHN Corp. All rights Reserved. 
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nhncorp.usf.core.service;

import java.util.HashMap;
import java.util.Map;

import com.nhncorp.usf.core.config.runtime.Action;
import com.nhncorp.usf.core.config.runtime.BusinessObject;
import com.nhncorp.usf.core.config.runtime.Method;
import com.nhncorp.usf.core.exception.ExceptionHandler;
import com.nhncorp.usf.core.service.MethodReturn.ReturnType;

/**
 * @author Web Platform Development Team.
 */
public class ServiceExecutionContext {
    /**
     * enum
     */
    public enum MethodType {
        sequential, parallel
    };

    private Action action;
    private BusinessObject bo;
    private Method method;
    private Map<String, Object> attributes;
    private MethodType methodType;
    private Map<String, Object> methodParameter;
    private ExceptionHandler exceptionHandler;
    private ReturnType returnType;
    private boolean enableAddCache;

    /**
     * Instantiates a new service execution context.
     *
     * @param initialzeAttributes the initialze attributes
     */
    public ServiceExecutionContext(Map<String, Object> initialzeAttributes) {
        if (initialzeAttributes == null) {
            attributes = new HashMap<String, Object>();
        } else {
            attributes = initialzeAttributes;
        }
    }

    /**
     * Gets the exception handler.
     *
     * @return the exception handler
     */
    public ExceptionHandler getExceptionHandler() {
        return exceptionHandler;
    }

    /**
     * Sets the exception handler.
     *
     * @param exceptionHandler the new exception handler
     */
    public void setExceptionHandler(ExceptionHandler exceptionHandler) {
        this.exceptionHandler = exceptionHandler;
    }

    /**
     * Gets the action.
     *
     * @return the action
     */
    public Action getAction() {
        return action;
    }

    /**
     * Sets the action.
     *
     * @param action the new action
     */
    public void setAction(Action action) {
        this.action = action;
    }

    /**
     * Gets the bo.
     *
     * @return the bo
     */
    public BusinessObject getBo() {
        return bo;
    }

    /**
     * Sets the bo.
     *
     * @param bo the new bo
     */
    public void setBo(BusinessObject bo) {
        this.bo = bo;
    }

    /**
     * Gets the method.
     *
     * @return the method
     */
    public Method getMethod() {
        return method;
    }

    /**
     * Sets the method.
     *
     * @param method the new method
     */
    public void setMethod(Method method) {
        this.method = method;
    }

    /**
     * Gets the attribute.
     *
     * @param key the key
     * @return the attribute
     */
    public Object getAttribute(String key) {
        return attributes.get(key);
    }

    /**
     * Sets the attribute.
     *
     * @param key   the key
     * @param value the value
     */
    public void setAttribute(String key, Object value) {
        attributes.put(key, value);
    }

    /**
     * Gets the attributes.
     *
     * @return the attributes
     */
    public Map<String, Object> getAttributes() {
        return attributes;
    }

    /**
     * Gets the method type.
     *
     * @return the method type
     */
    public MethodType getMethodType() {
        return methodType;
    }

    /**
     * Sets the method type.
     *
     * @param methodType the new method type
     */
    public void setMethodType(MethodType methodType) {
        this.methodType = methodType;
    }

    /**
     * Gets the method parameter.
     *
     * @return the method parameter
     */
    public Map<String, Object> getMethodParameter() {
        return methodParameter;
    }

    /**
     * Sets the method parameter.
     *
     * @param methodParameter the method parameter
     */
    public void setMethodParameter(Map<String, Object> methodParameter) {
        this.methodParameter = methodParameter;
    }

    /**
     * Gets the return type.
     *
     * @return the return type
     */
    public ReturnType getReturnType() {
        return returnType;
    }

    /**
     * Sets the return type.
     *
     * @param returnType the new return type
     */
    public void setReturnType(ReturnType returnType) {
        this.returnType = returnType;
    }

    /**
     * Cleanup method scope.
     */
    public void cleanupMethodScope() {
        this.method = null;
        this.methodParameter = null;
        this.methodType = null;
        this.returnType = null;
    }

    /**
     * @return Object
     * @throws CloneNotSupportedException the CloneNotSupportedException
     * @see java.lang.Object#clone()
     */
    @Override
    public Object clone() throws CloneNotSupportedException {
        ServiceExecutionContext clone = new ServiceExecutionContext(attributes);
        clone.setAction(action);
        clone.setBo(bo);
        clone.setMethod(method);
        clone.setExceptionHandler(exceptionHandler);
        clone.setMethodParameter(methodParameter);
        clone.setMethodType(methodType);
        clone.setReturnType(returnType);
        clone.setEnableAddCache(enableAddCache);
        return clone;
    }

    /**
     * @param obj Object
     * @return boolean
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        return this == obj;
    }

    /**
     * @return int
     * @see java.lang.Object#hashCode()
     */
    public int hashCode() {
        return super.hashCode();
    }

    /**
     * Checks if is enable add cache.
     *
     * @return true, if is enable add cache
     */
    public boolean isEnableAddCache() {
        return enableAddCache;
    }

    /**
     * Sets the enable add cache.
     *
     * @param enableAddCache the new enable add cache
     */
    public void setEnableAddCache(boolean enableAddCache) {
        this.enableAddCache = enableAddCache;
	}
}
